package com.gxuwz.stats.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxuwz.stats.entity.ResearchAward;
import com.gxuwz.stats.entity.User;
import com.gxuwz.stats.mapper.ResearchAwardMapper;
import com.gxuwz.stats.service.HumanResearchAwardService;
import com.gxuwz.stats.service.NatureResearchAwardService;
import com.gxuwz.stats.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HumanResearchAwardServiceImpl  extends ServiceImpl<ResearchAwardMapper, ResearchAward> implements HumanResearchAwardService {

    @Autowired
    private UserService userService;

    @Override
    public IPage<ResearchAward> getHumanResearchAwardList(IPage<ResearchAward> page, QueryWrapper<ResearchAward> queryWrapper) {
        IPage<ResearchAward> resultPage = this.page(page,queryWrapper);
        for(ResearchAward researchAward : resultPage.getRecords()){
            Integer userId = researchAward.getUserId();
            if(userId != null){
                User user = userService.getById(userId);
                if(user != null){
                    researchAward.setUsername(user.getUsername());
                }
            }
        }
        return  resultPage;
    }
}
